package com.hkts.naturalgas.performance.service.serviceimpl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hkts.naturalgas.performance.entity.HkPictureInfo;
import com.hkts.naturalgas.performance.mapper.HkPictureInfoMapper;
import com.hkts.naturalgas.performance.service.IHkPictureInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.apache.commons.lang.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import java.util.List;
/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yck
 * @since 2021-04-08
 */
@Service
@Transactional
public class HkPictureInfoServiceImpl extends ServiceImpl<HkPictureInfoMapper, HkPictureInfo> implements IHkPictureInfoService {


@Autowired
private HkPictureInfoMapper hkPictureInfoMapper;

@Override
public IPage<HkPictureInfo> selectPage(Page<HkPictureInfo> page, HkPictureInfo hkPictureInfo){
        QueryWrapper<HkPictureInfo> query = Wrappers.query();
        QueryWrapper<HkPictureInfo> entityWrapper = getEntityWrapper(query, hkPictureInfo);
        return hkPictureInfoMapper.selectPage(page, entityWrapper);
        }




@Override
public List<HkPictureInfo> selectList(HkPictureInfo hkPictureInfo){
        QueryWrapper<HkPictureInfo> query = Wrappers.query();
        QueryWrapper<HkPictureInfo> entityWrapper = getEntityWrapper(query, hkPictureInfo);
        return hkPictureInfoMapper.selectList(entityWrapper);
        }

/**
 *  公共查询条件
 * @param entityWrapper
 * @return
 */
public QueryWrapper<HkPictureInfo> getEntityWrapper(QueryWrapper<HkPictureInfo> entityWrapper,HkPictureInfo hkPictureInfo){
        //条件拼接
                if(StringUtils.isNotBlank(hkPictureInfo.getPictureKey())){
                entityWrapper.like(HkPictureInfo.PICTURE_KEY,hkPictureInfo.getPictureKey());
                }
                if(StringUtils.isNotBlank(hkPictureInfo.getPictureUrl())){
                entityWrapper.like(HkPictureInfo.PICTURE_URL,hkPictureInfo.getPictureUrl());
                }
        return entityWrapper;
        }
        }
